﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class PayBack : IAccessible<P_PayBack, PayBack>, ILogicEntity<P_PayBack, PayBack>
    {
        public int ID { get; set; }
        public string UserName { get; set; }
        public int ProjectID { get; set; }
        public int PolicyID { get; set; }
        public int InvestmentID { get; set; }
        public int RepaymentPlanItemID { get; set; }
        public decimal Rate { get; set; }
        public decimal PayBackInterest { get; set; }
        public decimal PayBackPrincipal { get; set; }
        public decimal PayBackedInterest { get; set; }
        public decimal PayBackedPrincipal { get; set; }
        public int CycleAmount { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public DateTime CreateTime { get; set; }
        public ItemStatus Status { get; set; }

        protected override void Covariant(P_PayBack model)
        {
            if (model != null)
            {
                this.CreateTime = model.CreateTime;
                this.CycleAmount = model.CycleAmount;
                this.EndDate = model.EndDate;
                this.ID = model.ID;
                this.InvestmentID = model.InvestmentID;
                this.PayBackedInterest = model.PayBackedInterest;
                this.PayBackedPrincipal = model.PayBackedPrincipal;
                this.PayBackInterest = model.PayBackInterest;
                this.PayBackPrincipal = model.PayBackPrincipal;
                this.PolicyID = model.PolicyID;
                this.ProjectID = model.ProjectID;
                this.Rate = model.Rate;
                this.RepaymentPlanItemID = model.RepaymentPlanItemID;
                this.StartDate = model.StartDate;
                this.Status = (ItemStatus)model.Status;
                this.UserName = model.UserName;
            }
        }

        protected override P_PayBack Inverter(PayBack model)
        {
            if (model != null)
            {
                return new P_PayBack()
                {
                    CreateTime = model.CreateTime,
                    CycleAmount = model.CycleAmount,
                    EndDate = model.EndDate,
                    ID = model.ID,
                    InvestmentID = model.InvestmentID,
                    PayBackedInterest = model.PayBackedInterest,
                    PayBackedPrincipal = model.PayBackedPrincipal,
                    PayBackInterest = model.PayBackInterest,
                    PayBackPrincipal = model.PayBackPrincipal,
                    PolicyID = model.PolicyID,
                    ProjectID = model.ProjectID,
                    Rate = model.Rate,
                    RepaymentPlanItemID = model.RepaymentPlanItemID,
                    StartDate = model.StartDate,
                    Status = (int)model.Status,
                    UserName = model.UserName
                };
            }
            return null;
        }

        public PayBack Set(P_PayBack dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
